package it.frusso.android.notepad;

import java.io.File;

import android.app.AlertDialog;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

public class PreferenceActivity extends android.preference.PreferenceActivity {

	EditTextPreference folderPathEditText = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);
	
		// Verifica la validità del folderPath
		folderPathEditText = (EditTextPreference) findPreference("folderPath");
		folderPathEditText.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				File newFolder = new File((String)newValue);
				if (!newFolder.isDirectory()) {
					Log.d(Const.LOG_TAG, "Invalid folder : " + newFolder.getAbsolutePath());
					Toast toast = Toast.makeText(getBaseContext(), null, Toast.LENGTH_SHORT);
					toast.setGravity(Gravity.CENTER, 0, 0);
					toast.setText(R.string.preferenceInvalidFolderPath);
					toast.show();
					return false;
				}
				return true;
			}
		});
		
	}
	
	
}
